<!DOCTYPE HTML>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<meta charset="utf-8">
<head th:include="include :: header"></head>
<link th:href="@{/ajax/libs/summernote/summernote.css}" rel="stylesheet"/>
<link th:href="@{/ajax/libs/summernote/summernote-bs3.css}" rel="stylesheet"/>
<body class="white-bg">
<div class="wrapper wrapper-content animated fadeInRight ibox-content">
    <form class="form-horizontal m" id="form-wdyNotice-edit" th:object="${wdyNotice}">
        <input id="id" name="id" th:field="*{id}" type="hidden">
        <div class="form-group">
            <label class="col-sm-3 control-label">标题：</label>
            <div class="col-sm-8">
                <input id="noticeName" name="noticeName" th:field="*{noticeName}" class="form-control" type="text">
            </div>
        </div>

        <div class="form-group">
            <label class="col-sm-3 control-label">发布时间：</label>
            <div class="col-sm-8">
                <input id="releaseTime" name="releaseTime"
                       th:value="*{#dates.format(releaseTime, 'yyyy-MM-dd HH:mm:ss')}" class="form-control time-input"
                       type="text">
            </div>
        </div>


        <div class="form-group">
            <label class="col-sm-3 control-label">新闻图片：</label>
            <div class="col-sm-8">
                <input id="noticeImage" name="noticeImage" th:field="*{noticeImage}" class="form-control" type="hidden">
                <input class="form-control" type="file" onchange="sendFile(null, this, 'noticeImage')" accept="image/*">
                <img id="image" src="" th:src="*{noticeImage}">
            </div>
        </div>

        <div class="form-group">
            <label class="col-sm-3 control-label">新闻描述：</label>
            <div class="col-sm-8">
                <input id="imageList" name="imageList" th:field="*{imageList}" type="hidden">
                <div id="editorImage" class="summernote"></div>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">新闻内容：</label>
            <div class="col-sm-8">
                <input id="noticeDetail" name="noticeDetail" th:field="*{noticeDetail}" type="hidden">
                <div id="editor" class="summernote"></div>
            </div>
        </div>


        <div class="form-group">
            <label class="col-sm-3 control-label">作者：</label>
            <div class="col-sm-8">
                <input id="noticeAuthor" name="noticeAuthor" th:field="*{noticeAuthor}" class="form-control"
                       type="text">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">中英文 0中文1英文：</label>
            <div class="col-sm-8">
                <input id="zyType" name="zyType" th:field="*{zyType}" class="form-control" type="text">
            </div>
        </div>

        <div class="form-group">
            <label class="col-sm-3 control-label">商品分类：</label>
            <div class="col-sm-8">
                <select name="noticeType" class="form-control m-b" th:with="type=${@dict.getType('wdy_notice_type')}">
                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}" th:field="*{noticeType}"></option>
                </select>
            </div>
        </div>

        <div class="form-group">
            <label class="col-sm-3 control-label">删除标志（0代表存在 1代表删除）：</label>
            <div class="col-sm-8">
                <input id="delFlag" name="delFlag" th:field="*{delFlag}" class="form-control" type="text">
            </div>
        </div>

        <div class="form-group">
            <label class="col-sm-3 control-label">备注信息：</label>
            <div class="col-sm-8">
                <input id="remark" name="remark" th:field="*{remark}" class="form-control" type="text">
            </div>
        </div>
    </form>
</div>
<div th:include="include::footer"></div>
<script th:src="@{/ajax/libs/summernote/summernote.min.js}"></script>
<script th:src="@{/ajax/libs/summernote/summernote-zh-CN.js}"></script>
<script type="text/javascript">
    var prefix = ctx + "system/wdyNotice";
    $("#form-wdyNotice-edit").validate({
        rules: {
            xxxx: {
                required: true,
            },
        },
        focusCleanup: true
    });

    $(function() {
        $('.summernote').summernote({
            height : '220px',
            lang : 'zh-CN',
            callbacks: {
                onImageUpload: function (files) {
                    sendFile(files[0], this, 'noticeDetail');
                }
            }
        });
        $('.summernote').summernote({
            height : '220px',
            lang : 'zh-CN',
            callbacks: {
                onImageUpload: function (files) {
                    sendFile(files[0], this, 'imageList');
                }
            }
        });
        var contentIL = $("#imageList").val();
        $('#editorImage').summernote('code', contentIL);
        var contentND = $("#noticeDetail").val();
        $('#editor').summernote('code', contentND);
    });


    function submitHandler() {
        if ($.validate.form()) {
            var sHTMLimageList = $('.summernote').summernote('code');
            $("#imageList").val(sHTMLimageList);
            var sHTML = $('.summernote').eq(1).summernote('code');
            $("#noticeDetail").val(sHTML);
            $.operate.save(prefix + "/edit", $('#form-wdyNotice-edit').serialize());
        }
    }


    // 上传文件
    function sendFile(file, obj, sendType) {
        var data = new FormData();
        if (sendType == 'noticeImage')
            data.append("file", obj.files[0]);
        else if (sendType == 'imageList')
            data.append("file", file);
        else
            data.append("file", file);
        $.ajax({
            type: "POST",
            url: ctx + "common/upload",
            data: data,
            cache: false,
            contentType: false,
            processData: false,
            dataType: 'json',
            success: function (result) {
                if (result.code == web_status.SUCCESS) {
                    if (sendType == 'noticeImage') {
                        $('#image').attr('src', result.url);
                        $('#noticeImage').val(result.url);
                    } else if (sendType == 'imageList') {
                        $(obj).summernote('editorImage.insertImage', result.url, result.fileName);
                    } else {
                        $(obj).summernote('editor.insertImage', result.url, result.fileName);
                    }

                } else {
                    $.modal.alertError(result.msg);
                }
            },
            error: function (error) {
                $.modal.alertWarning("图片上传失败。");
            }
        });
    }


</script>
</body>
</html>
